package org.gl.training.gwt.shared.utils;

import java.util.ArrayList;
import java.util.List;

import org.gl.training.gwt.shared.model.TaskVO;
import org.gl.training.gwt.shared.model.UserVO;

import com.smartgwt.client.widgets.grid.ListGridRecord;

public class RecordUtils {

	public static List<ListGridRecord> getUserGridRecords(
			List<UserVO> userVOList) {
		List<ListGridRecord> userRecords = new ArrayList<ListGridRecord>();
		for (UserVO userVO : userVOList) {
			ListGridRecord userRecord = new ListGridRecord();
			userRecord.setAttribute("id", userVO.getId());
			userRecord.setAttribute("userName", userVO.getUserName());
			userRecord.setAttribute("fullName", userVO.getFullName());
			userRecord.setAttribute("email", userVO.getEmail());
			userRecord.setAttribute("userStatus", userVO.getUserStatus());
			userRecords.add(userRecord);
		}
		return userRecords;
	}

	public static List<ListGridRecord> getTaskGridRecords(
			List<TaskVO> taskVOList) {
		List<ListGridRecord> taskRecords = new ArrayList<ListGridRecord>();
		for (TaskVO taskVO : taskVOList) {
			ListGridRecord taskRecord = new ListGridRecord();
			taskRecord.setAttribute("id", taskVO.getId());
			taskRecord.setAttribute("event", taskVO.getEvent());
			taskRecord.setAttribute("time", taskVO.getTime());
			taskRecord.setAttribute("estimateDuration",
					taskVO.getEstimateDuration());
			taskRecord.setAttribute("actualDuration",
					taskVO.getActualDuration());
			taskRecord.setAttribute("comments", taskVO.getComments());
			taskRecords.add(taskRecord);
		}
		return taskRecords;
	}

	public static TaskVO getTaskVO(ListGridRecord record) {
		TaskVO taskVO = new TaskVO();
		taskVO.setId(record.getAttributeAsInt("id"));
		taskVO.setEvent(record.getAttributeAsString("event"));
		taskVO.setTime(record.getAttributeAsString("time"));
		taskVO.setEstimateDuration(record
				.getAttributeAsString("estimateDuration"));
		taskVO.setActualDuration(record.getAttributeAsString("actualDuration"));
		taskVO.setComments(record.getAttributeAsString("comments"));
		return taskVO;
	}
}
